/**
 * Qiangungun.com Inc.
 * Copyright (c) 2015-2015 All Rights Reserved.
 */
package com.qiangungun.report.biz.share;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @author hangdahong
 * @version $Id: ActionContext.java, v 0.1 2015年3月3日 下午8:25:26 hangdahong Exp $
 */
public class ActionContext {
    
    private Object request;

    private Object response;

    private boolean end;

    public boolean isEnd() {
        return end;
    }

    public void end() {
        end = true;
    }

    private final Map<String, Object> param = new HashMap<String, Object>();

    private static final ThreadLocal<ActionContext> CONTEXT = new ThreadLocal<ActionContext>() {
        @Override
        protected ActionContext initialValue() {
            return new ActionContext();
        }
    };

    public void setParam(String key, Object value) {
        this.param.put(key, value);
    }

    public void putParam(Map<String, Object> map) {
        this.param.putAll(map);
    }

    public Object getParam(String key) {
        return this.param.get(key);
    }

    public static ActionContext getContext() {
        return CONTEXT.get();
    }

    public void setRequest(Object request) {
        this.request = request;
    }

    public static void removeContext() {
        CONTEXT.remove();
    }

    public void clearParam() {
        this.param.clear();
    }

    public Object getRequest() {
        return this.request;
    }

    public Object getResponse() {
        return this.response;
    }

    public void setResponse(Object response) {
        this.response = response;
    }

    protected ActionContext() {
    }

}
